package com.fs.base.repository;

import java.util.Collection;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.fs.base.pojo.MenuMotion;
import com.fs.base.pojo.RoleRight;

/**
 * @author TiddlerCJ
 */
public interface RoleRightRepository extends JpaRepository<RoleRight,String>, JpaSpecificationExecutor<RoleRight>{
	@Transactional
	void deleteByRoleId(String roleId);
	
	List<RoleRight> findByRoleId(String roleId);
	
	//@Query("select mu FROM Menu mu where mu.id in( select m.menuId from MenuMotion m where m.id in ( select rmm.menuMotionId from  RoleRight rmm where rmm.roleId in ( select ur.roleId from UserRole ur where ur.userId = ?1 ) ) ) order by mu.menuOrder asc")
	//List<Menu> findUserRolesMenu(String userId);
	
	//@Query("select m from MenuMotion m where m.id in ( select rmm.menuMotionId from RoleRight rmm where rmm.roleId in ( select ur.roleId from UserRole ur where ur.userId = ?1 ) ) order by m.motionOrder asc ")
	//List<MenuMotion> findUserRolesMenuMotion(String userId);
	
	@Query("select m from MenuMotion m where m.id in ( select rmm.menuMotionId from RoleRight rmm where rmm.roleId in ?1 ) order by m.motionOrder asc ")
	List<MenuMotion> findUserRolesMenuMotion(Collection<String> roleIds);
	
}
